<template>
  <div class="tp-selection">
    <slot name="left"></slot>
    <div
      class="tp-selection_left"
    >
      <mk-checkbox
        v-model="checkedValue"
        @change="checked"
      >
        全选(单次批量操作支持1千条/导出支持1万条)
      </mk-checkbox>
      <div>
        <span
          class="export-detail"
          @click="handleExport"
        >
          <i :class="['iconfont', exportObj.icon]"></i>
          {{ exportObj.text }}
        </span>
      </div>
    </div>
    <slot name="center"></slot>
    <div
      class="tp-selection_right"
    >
      <span class="selection-num">
        共选择
        <span>{{ selectionNum }}</span>
        项
      </span>
      <span
        class="action-box_right--cancel"
        @click="cancelSelection"
      >
        取消
      </span>
    </div>
    <slot name="right"></slot>
  </div>
</template>

<script>
export default {
  name: 'TpSelection',
  props: {
    num: {
      type: Number,
      default: 0
    },
    total: {
      type: Number,
      default: 0
    },
    exportObj: {
      type: Object,
      default () {
        return {
          text: '导出',
          icon: 'icon-ds-daochu'
        }
      }
    }
  },
  data () {
    return {
      checkedValue: '',
      selectionNum: 0
    }
  },
  watch: {
    num (to) {
      this.selectionNum = to
    }
  },
  methods: {
    handleExport () {
      this.$emit('export')
    },
    checked () {
      if (this.checkedValue) {
        this.selectionNum = this.total
        this.$emit('checked')
      } else {
        this.cancelSelection()
      }
    },
    cancelSelection () {
      this.selectionNum = 0
      this.checkedValue = ''
      this.$emit('cancel')
    }
  }
}
</script>

<style scoped lang="scss">
  .tp-selection {
    width: 100%;
    height: 50px;
    line-height: 50px;
    flex-grow: 0;
    flex-shrink: 0;
    display: flex;
    padding: 0 10px;
    justify-content: space-between;
    align-items: center;
    box-sizing: border-box;
    box-shadow: 0 -1px 4px 0 rgba(0, 0, 0, 0.15);

    .tp-selection_left {
      display: flex;
      height: 50px;
      align-items: center;

      /deep/.el-checkbox__label {
        font-size: 13px;
        color: #8c8c8c;
      }

      .export-detail {
        color: #595959;
        font-size: 13px;
        cursor: pointer;
        margin-left: 20px;
      }
    }

    .tp-selection_right {
      line-height: 50px;
      font-size: 13px;
      -moz-user-select: none;
      -webkit-user-select: none;
      -ms-user-select: none;
      -khtml-user-select: none;
      -o-user-select: none;
      user-select: none;

      .selection-num {
        span {
          color: #009cff;
        }
      }

      .action-box_right--cancel {
        margin-left: 10px;
        color: #009cff;
      }
    }
  }
</style>
